<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Manual Test Scripts</title>
  <link type="text/css" rel="stylesheet" href="../mbgdoc/mbgstyle.css"/>
</head>
<body>
<h1>Manual Test Scripts</h1>
<p>This page lists scripts for testing the different parts of the MyBatis Generator
UI.  This information may also be helpful in learning how to use the different parts
of the Eclipse user interface for MyBatis Generator.</p>
<h2>Setup</h2>
<ol>
  <li>Make sure that MySQL is installed and running.  The following scripts also assume
      that the password for <code>root</code> is also <code>root</code></li>
  <li>Make sure that you have downloaded the MySQL Connector for Java and unzipped
      it somewhere on your local drive.  The following scripts assume the
      MySQL JDBC driver is located at
      "/JavaTools/mysql-connector-java-5.1.12/mysql-connector-java-5.1.12-bin.jar".</li>
  <li>If you have not created the test database already, then execute the
      following script:
      <pre>

drop schema if exists mbgtest;
create schema mbgtest;
use mbgtest;
create table a (id int not null, description varchar(50), primary key(id));
create table b (id int not null, description varchar(50), primary key(id));
create table c (id int not null, description varchar(50), primary key(id));
create table d (id int not null, description varchar(50), primary key(id));
create table e (id int not null, description varchar(50), primary key(id));
create table f (id int not null, description varchar(50), primary key(id));
create table g (id int not null, description varchar(50), primary key(id));
create table h (id int not null, description varchar(50), primary key(id));
create table i (id int not null, description varchar(50), primary key(id));
create table j (id int not null, description varchar(50), primary key(id));
      </pre>
  </li>
  <li>Make sure that the new version of the plugin has been built.</li>
</ol>

<h2>Tests</h2>
<p>The following tests are intended to be executed in the order listed.  Some
tests build on items created in previous tests.</p>
<h3>Installation</h3>
<ol>
  <li>Install a fresh version of Eclipse (version 3.6.1 or later)</li>
  <li>Open the fresh Eclipse install, and create a new (empty) workspace</li>
  <li>Configure a local update site to point to the newly generated site
      (Help&gt;Install New Software...)</li>
  <li>Show all versions of the feature</li>
  <li>Install the oldest version of the feature</li>
  <li>Restart Eclipse</li>
  <li>Do a regular software update and verify that the newest version of the
      feature is listed as an install option (this may also install other Eclipse updates)</li>
  <li>Restart Eclipse</li>
  <li>Verify that the latest version of the feature is listed as installed</li>
</ol>

<h3>Documentation</h3>
<ol>
  <li>Open the Eclipse help (Help&gt;Help Contents)</li>
  <li>Verify that the book "MyBatis Generator User's Guide" appears
      in the contents.</li>
  <li>Verify that every item in the contents points to a valid page,
      and that all pages are referenced in the table of contents.  This is
      especially important if new packages or help pages have been added anywhere.</li>
  <li>Verify that the core MyBatis Generator documentation pages do not show the options
      to show or hide the menu.  These options should be disabled by the style sheet.</li>
  <li>Verify that the latest version of the release notes is shown both in the
      Eclipse UI documentation, and the Core MyBatis Generator documentation.</li>
</ol>

<h3>New File Wizard</h3>
<ol>
  <li>Create a new JavaProject called "MBGTest".  Make sure there is a separate source folder
      called <code>src</code></li>
  <li>Add an additional source folder called <code>generatedsrc</code></li>
  <li>Configure the build path to add the iBATIS 2 JAR file (typically an external JAR
     in the local maven repo)</li>
  <li>Create a new package in the <code>src</code> folder called <code>config</code></li>
  <li>Make a new configuration file:
    <ol type="a">
      <li>Right click on the <code>config</code> package</li>
      <li>Select New&gt;Other&gt;MyBatis&gt;MyBatis Generator Configuration File</li>
      <li>Press Next</li>
      <li>Verify that Location is set to "MBGTest/src/config"</li>
      <li>Verify that File Name is set to "generatorConfig.xml"</li>
      <li>Press Finish</li>
      <li>Verify that an editor opens with a skeleton configuration File</li>
    </ol></li>
    <li>Right click on the new file, then take the option "Generate MyBatis/iBATIS Artifacts"</li>
    <li>Verify that an error dialog is shown with the detail message "Exception getting JDBC Driver"</li>
    <li>Press "OK" to dismiss the dialog</li>
</ol>

<h3>Generate MyBatis/iBATIS Artifacts</h3>
<ol>
  <li>Open an editor on the file "generatorConfig.xml" that you created in the previous test</li>
  <li>Change the contents of the file to the following:
    <pre>

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" &gt;
&lt;generatorConfiguration&gt;
  &lt;classPathEntry location="/JavaTools/mysql-connector-java-5.1.17/mysql-connector-java-5.1.17-bin.jar" /&gt;
  &lt;context id="context1" targetRuntime="MyBatis3" &gt;
    &lt;jdbcConnection driverClass="com.mysql.jdbc.Driver"
      connectionURL="jdbc:mysql://localhost/mbgtest"
      userId="root" password="root" &gt;
    &lt;/jdbcConnection&gt;
    &lt;javaModelGenerator targetPackage="gen.model" targetProject="MBGTest" /&gt;
    &lt;sqlMapGenerator targetPackage="gen.mapper" targetProject="MBGTest" /&gt;
    &lt;javaClientGenerator targetPackage="gen.mapper" targetProject="MBGTest" type="XMLMAPPER" /&gt;
    &lt;table tableName="a" /&gt;
  &lt;/context&gt;

  &lt;context id="context2" targetRuntime="MyBatis3" &gt;
    &lt;jdbcConnection driverClass="com.mysql.jdbc.Driver"
      connectionURL="jdbc:mysql://localhost/mbgtest"
      userId="root" password="root" &gt;
    &lt;/jdbcConnection&gt;
    &lt;javaModelGenerator targetPackage="gen.src.model" targetProject="MBGTest/generatedsrc" /&gt;
    &lt;sqlMapGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" /&gt;
    &lt;javaClientGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" type="XMLMAPPER" /&gt;
    &lt;table schema="mbgtest" tableName="%" /&gt;
  &lt;/context&gt;
&lt;/generatorConfiguration&gt;
    </pre></li>
    <li>Change the location of the JDBC driver in the <code>&lt;classPathEntry&gt;</code> element
      if different on your system</li>
    <li>Save the file</li>
    <li>Right click on the file, then take the option "Generate MyBatis/iBATIS Artifacts"</li>
    <li>Verify that code is generated in the two different source folders.  Code for table "a"
        should be in the "src" folder, code for tables "a" through "j" should be in the
        "generatedsrc" folder.  Verify that there are no compilation errors or warnings.</li>
</ol>

<h3>Java File Merger</h3>
<ol>
  <li>Open the Java file <code>gen.model.A.java</code> in the "src" folder</li>
  <li>Note the time of generation of the file from one of the <code>@mbggenerated</code> comments</li>
  <li>Add a private field of any type called <code>mergetest</code> and generate a getter and setter
      for the field.</li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file from the last test, and then
      take the option "Generate MyBatis/iBATIS Artifacts"</li>
  <li>Verify that the progress bar is reasonably accurate</li>
  <li>Open the Java file <code>gen.model.A.java</code> in the "src" folder</li>
  <li>Verify that the time of generation is later than the time noted above</li>
  <li>Verify that the field <code>mergetest</code>, and its getter and setter remain
    in the file (they will have been moved to the bottom of the file)</li>
  <li>Open the configuration file from the last test.</li>
  <li>Change the Java client type in <code>context1</code> to <code>SPRING</code></li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file, and then
      take the option "Generate MyBatis/iBATIS Artifacts"</li>
  <li>Verify that <code>src.dao.ADAOImpl</code> now extends <code>SqlMapClientDaoSupport</code>.
      Note that there will be several errors in the workspace now because of the new dependencies
      on Spring that were generated.</li>

  <li>Re open the configuration file.</li>
  <li>Change the Java client type in <code>context1</code> back to <code>GENERIC-CI</code></li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file, and then
      take the option "Generate MyBatis/iBATIS Artifacts"</li>
  <li>Verify that <code>src.dao.ADAOImpl</code> doesn't extend anything.  There will be one
      error in the file related to the Spring import (the Java merger does not reconcile all
      imports).  Delete the import and verify that there are no other errors in the
      workspace.  Also, verify that the field <code>mergetest</code> and its
      associated getter and setter still exist.</li>
</ol>

<h3>Ant Build</h3>
<ol>
  <li>Close Eclipse if it is still open, then reopen Eclipse (this resets the plugin classloader
      for the custom classpath portion of the test).</li>
  <li>Open the configuration file from the last test.</li>
  <li>Delete the <code>&lt;classPathEntry&gt;</code> element from the file.</li>
  <li>Save and close the file.</li>
  <li>Create a new file <code>build.xml</code> in the "MBGTest/src/config" package.</li>
  <li>Change the contents of the new file to the following:
    <pre>

&lt;project default="runMyBatisGenerator"&gt;
  &lt;target name="runMyBatisGenerator"&gt;
    &lt;eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                         property="thePath"/&gt;
    &lt;mybatis.generate configfile="${thePath}" &gt;
    &lt;/mybatis.generate&gt;
  &lt;/target&gt;
&lt;/project&gt;
    </pre>
  </li>
  <li>Save and close the file.</li>
  <li>Delete the Java file <code>gen.dao.ADAO.java</code>.  There will now be errors in the
      workspace.</li>
  <li>Right click on the new <code>build.xml</code> file, then select the
      menu option "Run As&gt;Ant Build...".  You should see the Ant launch configuration
      dialog open.</li>
  <li>Select the "JRE" tab, then select the "Run in the same JRE as the workspace" radio
      button.</li>
  <li>Press the "Run" button</li>
  <li>You should see an error dialog open with a runtime exception stating "Exception
      getting JDBC Driver".  Press "OK" to dismiss the dialog.</li>
  <li>Right click on the new <code>build.xml</code> file, then select the
      menu option "Run As&gt;Ant Build...".  You should see the Ant launch configuration
      dialog open.</li>
  <li>Select the "Classpath" tab, then add the MySQL driver to "User Entries"</li>
  <li>Press the "Run" button</li>
  <li>After MyBatis Generator runs, you should see a "BUILD SUCCESSFUL" message.
      You may see build warnings related to log4j if it is installed in your Eclipse
      distribution.  You can safely ignore these warnings.
  </li>
  <li>Verify that the workspace errors are gone.</li>
</ol>

</body>
</html>
